package com.cskaoyan.controller.wechat;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.user.Feedback;
import com.cskaoyan.bean.user.User;
import com.cskaoyan.mapper.FeedbackMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @author dengww
 * @create 2020/5/5 7:29
 */
@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {

    @Autowired
    FeedbackMapper feedbackMapper;

    @PostMapping("submit")
    public BaseRespVo submitFeekBackInfo(@RequestBody Map map) {
        Feedback feedback = new Feedback();
        feedback.setAddTime(new Date());
        feedback.setUpdateTime(new Date());
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        feedback.setUserId(user.getId());
        feedback.setUsername(user.getUsername());
        feedback.setMobile(map.get("mobile")+"");
        feedback.setStatus(0);
        feedback.setContent(map.get("content")+"");
        feedback.setFeedType(map.get("feedType")+"");
        feedback.setHasPicture((boolean)map.get("hasPicture"));
        feedback.setPicUrls(map.get("picUrls")+"");
        feedback.setDeleted(false);
        feedbackMapper.insert(feedback);
        BaseRespVo<Object> respVo = new BaseRespVo<>(0, null, "成功");
        return respVo;
    }
}
